#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[]) {
    int fd;
    char *buffer;

    if (argc != 2) {
        printf("Usage: %s <value>\n", argv[0]);
        printf("Value should be '1' to turn on LED or '0' to turn off LED\n");
        return 1;
    }

    buffer = argv[1];

    // 打开设备文件
    fd = open("/dev/led_ctl", O_WRONLY);
    if (fd < 0) {
        perror("Failed to open the device file");
        return 1;
    }

    // 写入数据到设备文件
    if (write(fd, buffer, 1) != 1) {
        perror("Failed to write to the device file");
        close(fd);
        return 1;
    }

    // 关闭设备文件
    close(fd);

    printf("LED control value %c sent successfully\n", buffer[0]);
    return 0;
}
